package com.hmall.common.config;

import com.hmall.common.interceptor.LoginInterCeptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 注册拦截器的配置类
// DispatcherServlet 是 SpringMVC 的核心类，如果看到了这个类，说明有SpringMVC
@Configuration
@ConditionalOnClass(DispatcherServlet.class)
public class MvcConfig implements WebMvcConfigurer {

    // @Autowired
    // private LoginInterCeptor loginInterCeptor;

    // 注册我们的拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // WebMvcConfigurer.super.addInterceptors(registry);
        // 注册拦截器
        registry.addInterceptor( new LoginInterCeptor());
    }
}
